import { createRouter, createWebHistory } from "vue-router";
import type { RouteRecordRaw } from "vue-router";
import { pinia } from "@/store/index";
import { useSysStore } from "@/store/sys";
import { isNil } from "lodash";
// import { isEmpty, isUndefined } from "lodash";
const sysStore = useSysStore(pinia);



const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'login',
        component: () => import('@/views/Login.vue')
    },
    {
        path: '/404',
        name: '404',
        component: () => import('@/views/404/index.vue')
    },
    {
        path: '/main',
        name: 'main',
        component: () => import('@/views/layout/index.vue'),
        beforeEnter: (_to, _from) => {
            if (isNil(sysStore.oper.id) || sysStore.oper.id === 0) {
                router.push('/');
            }
        }
    },
    {
        path: '/:pathMatch(.*)*',
        redirect: '/404',
        name: 'errorUrl'
    }
];

const router = createRouter({
    // history: 路由器工作模式
    // history: createWebHashHistory(), // electron
    history: createWebHistory(),    // web
    
    routes
});

export default router;